/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.up.ling.irtg.gui;

import de.up.ling.irtg.automata.TreeAutomaton;
import de.up.ling.irtg.corpus.ChartComputationListener;
import de.up.ling.irtg.corpus.Instance;
import javax.swing.SwingUtilities;

/**
 *
 * @author koller
 */
public class ChartComputationProgressBar extends javax.swing.JDialog implements ChartComputationListener {
    private int numInstances;

    /**
     * Creates new form ChartComputationProgressBar
     */
    public ChartComputationProgressBar(java.awt.Frame parent, boolean modal, int numInstances) {
        super(parent, modal);
        initComponents();

        progressBar.setMaximum(numInstances);
        progressBar.setString("0/" + numInstances);
        this.numInstances = numInstances;
    }
    
    public void setLabelText(String text) {
        jLabel1.setText(text);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Chart computation progress");

        jLabel1.setText("Computing charts for unannotated corpus ...");

        progressBar.setString("0/100");
        progressBar.setStringPainted(true);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(progressBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(0, 107, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JProgressBar progressBar;
    // End of variables declaration//GEN-END:variables

    public void update(final int index, Instance instance, TreeAutomaton chart) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                progressBar.setValue(index+1);
                progressBar.setString("" + (index + 1) + "/" + numInstances);
            }
        });

    }
}
